package com.hqyj.controller;

import com.hqyj.config.PaySocketServer;
import com.hqyj.pojo.Cash;
import com.hqyj.pojo.TbDevice;
import com.hqyj.pojo.TbParkingUse;
import com.hqyj.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;

/**
 * @description:
 * @author: GP
 * @date: 2021/10/7-23:37
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;

    //支付成功异步回调
    //注意：请求方式注解必须PostMapping，不支持GetMapping
    @PostMapping("/testJson")
    public void test(HttpServletRequest request) throws IOException {
        //请求状态参数 trade_status，有两个值： 1 WAIT_BUYER_PAY 正在支付 2 TRADE_SUCCESS
        //支付成功
        System.out.println("支付状态："+ request.getParameter("trade_status"));

        if(request.getParameter("trade_status").equals("TRADE_SUCCESS")){
            System.out.println("发送信息给前端，提示支付完毕");
            PaySocketServer.SendMessage("ok");
        }
    }

    /**
     * 业主购买停车位
     * 127.0.0.1:8080/
     * @param tbParkingUse
     * @return
     */
    @PostMapping(value = "/payPark" ,consumes = "application/json")
    public HashMap<String, Object> payPark(@RequestBody TbParkingUse tbParkingUse){
        return payService.payPark(tbParkingUse);
    }


    /**
     * 未购买停车位用户支付停车费用
     * 127.0.0.1:8080/
     * @param tbParkingUse
     * @return
     */
    @PostMapping(value = "/payParkingFee" ,consumes = "application/json")
    public HashMap<String, Object> payParkingFee(@RequestBody TbParkingUse tbParkingUse){
        return payService.payParkingFee(tbParkingUse);
    }

    /**
     *维修押金
     * 127.0.0.1:8080/
     * @param cash
     * @return
     */
    @PostMapping(value = "cash" ,consumes = "application/json")
    public HashMap<String, Object> cash(@RequestBody Cash cash){
        return payService.cash(cash);
    }


    /**
    * @Author:YaoHaoHong
    * @Description:
     * 业主购买设备
    * @Date:2021/10/8 16:24
    */
    @PostMapping(value = "/payDevice",consumes = "application/json")
    public HashMap<String ,Object> payDevice(@RequestBody TbDevice tbDevice){
        return payService.payDevice(tbDevice);
    }
}
